package day07.concurrent04;

import java.util.concurrent.Executors;

/**
 * Executors 工具类，用于快速创建线程池
 */
public class Demo07 {
    public static void main(String[] args) {
        /*
        创建一个可根据需要创建新线程的线程池
        return new ThreadPoolExecutor(
            0, Integer.MAX_VALUE,
            60L, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>());
         */
        Executors.newCachedThreadPool();
        /*
            创建一个可重用固定线程数的线程池，以共享的无界队列方式来运行这些线程
            return new ThreadPoolExecutor(
                nThreads, nThreads,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>());

         */
        Executors.newFixedThreadPool(10);

        /*
             创建一个使用单个 worker 线程的 Executor
            return new FinalizableDelegatedExecutorService
            (new ThreadPoolExecutor(
                1, 1,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>()));
         */
        Executors.newSingleThreadExecutor();
    }
}
